import {request} from '../../network/index'
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		active: 0,
		limit:50,
		offset:1,
		initial:-1,
		type :-1,
		area :-1,
		singers:[],
		videoList:[],
		videoContent:[],
		offset:0,
		full:false,
		title:['视频','歌手'],
		titleActive:0,
		columns: ['热门','A', 'B', 'C', 'D', 'E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','#'],
		is:true,
		option1: [
      { text: '全部', value: -1 },
      { text: '华语', value: 7 },
      { text: '欧美', value: 96 },
      { text: '日本', value: 8 },
      { text: '韩国', value: 16 },
      { text: '其他', value: 0 },
    ],
    option2: [
      { text: '全部', value: -1 },
      { text: '男歌手', value: 1 },
      { text: '女歌手', value: 2 },
      { text: '乐队组合', value: 3 },
		],
    value1: -1,
    value2: -1,
	},
	toMv(){
		wx.navigateTo({
			url: '/pages/mv/mv',
		})
	},
	//tab标签切换数据
	async onChangeVideo(event) {
		let videoContent = await request('/video/group',{id:event.detail.name})
		this.setData({
			videoContent:videoContent.data.datas
		})
	},
	//点击title切换
	 change(event){
		let index = event.currentTarget.dataset.index
		this.setData({
			titleActive:index
		})
	},
	//滑动切换
	bindchange(event){
		this.setData({
			titleActive:event.detail.current
		})
		if(event.detail.current===1){
			this.getSingers(this.data.limit,this.data.offset,this.data.initial,this.data.type,this.data.area)
		}
	},
	//请求歌手数据
	async getSingers(limit,offset,initial,type,area){
		let singers = await request('/artist/list',{limit,offset,initial,type,area})
		console.log(singers);
		this.setData({
			singers:singers.data.artists
		})
	},

	//语种筛选歌手
	change1(value){
		this.data.area = value.detail
		console.log(value.detail);
		this.getSingers(this.data.limit,this.data.offset,this.data.initial,this.data.type,this.data.area)
	},
	//分类刷选歌手
	change2(value){
		this.data.type = value.detail
		this.getSingers(this.data.limit,this.data.offset,this.data.initial,this.data.type,this.data.area)
	},
	//字母刷选歌手
	onChange(event) {
		if(event.detail.value === '热门'){
			event.detail.value = -1
		}else if(event.detail.value === '#'){
			event.detail.value = 0
		}
		this.data.initial = event.detail.value
		this.getSingers(this.data.limit,this.data.offset,this.data.initial,this.data.type,this.data.area)
		this.selectComponent('#menu').toggle('false')
	 },
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
	
	},
	// scroll-view下拉刷新
	async pull(event){
		this.data.offset += 10
		console.log(this.data.offset);
		let videoContent = await request('/video/group',{id:event.target.dataset.vid,offset:this.data.offset})
		console.log(videoContent);
		this.setData({
			videoContent:videoContent.data.datas,
			full:false,
		})
	},
	//视频上拉加载
	topFull(event){
		
	},
	 toSingerDetail(event){
		let id = event.currentTarget.dataset.id
		wx.navigateTo({
			url: `/pages/singerMusic/singerMusic?id=${id}`,
		})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow:async function () {
			//tab切换标签和首页数据
			let viedos = await request('/video/category/list')
			let id = viedos.data.data[0].id
			const oneData = await request('/video/group',{id})
			this.setData({
				videoList:viedos.data.data,
				videoContent:oneData.data.datas
			})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		console.log('aaa');
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})